﻿using SqlSugar;
using System;
using System.Collections.Generic;

namespace Tools
{
    public class Sql
    {
        private ConnectionConfig connection = null;
        public SqlSugarClient db = null;
        public Sql()
        {
            ConfigHelper configHelper = new ConfigHelper();
            Dictionary<string, string> dic = configHelper.ReadAll();
            connection = new ConnectionConfig()
            {
                ConnectionString = "server='" + dic["SqlIP"] + "';initial catalog='" + dic["database"] + "';uid='" + dic["uid"] + "';pwd='" + dic["pwd"] + "'",
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute
            };
            db = new SqlSugarClient(connection);
        }
        public Sql(string IP)
        {
            ConfigHelper configHelper = new ConfigHelper();
            Dictionary<string, string> dic = configHelper.ReadAll();
            connection = new ConnectionConfig()
            {
                ConnectionString = "server='" + IP + "';initial catalog='" + dic["database"] + "';uid='" + dic["uid"] + "';pwd='" + dic["pwd"] + "'",
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute
            };
            db = new SqlSugarClient(connection);
        }
        [SugarTable("t_CMCC_ProdSN")]
        public class t_CMCC_ProdSN
        {
            [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
            public string parentsn { get; set; }
            public string snimei { get; set; }
            public int status { get; set; }
            public int issend { get; set; }
            public DateTime createtime { get; set; }
        }
        [SugarTable("t_CMCC_WriteSN")]
        public class t_CMCC_WriteSN
        {
            [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
            public DateTime prodate { get; set; }
            public string result { get; set; }
            public string idproductionline { get; set; }
        }
        [SugarTable("t_CMCC_SynTestNew")]
        public class t_CMCC_SynTestNew
        {
            [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
            public string prodsn { get; set; }
            public DateTime prodate { get; set; }
            public string result { get; set; }
            public string idproductionline { get; set; }
        }
        public bool SqlCheck()
        {
            try
            {
                db.Open();
                db.Close();
                db.Dispose();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
